package com.itheima.tanhua.service;

import cn.hutool.core.convert.Convert;
import com.itheima.tanhua.Dto.LocationDto;
import com.itheima.tanhua.api.mongodb.BaiduLocationApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class BaiduService {

    @DubboReference
    private BaiduLocationApi baiduLocationApi;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    //百度地图上报地理信息
    public void baiduLocation(LocationDto dto) {

        //获取用户的id
        Long uid = Convert.toLong(stringRedisTemplate.opsForValue().get("CHECK_ID"));
        dto.setUserId(uid);
        //更新百度地图上的位置
        boolean result = baiduLocationApi.updateLocation(dto);
        if (!result){
            //更新失败
            throw new RuntimeException("百度地图更新失败");
        }
    }
}
